import axios from 'axios'
const imageUpTo = (obj) => {
  return new Promise((resolve, reject) => {
    axios({
      url: '/api/sys-digital/dsf/oss2/upload3',
      data: obj, 
      method: 'post',
      headers: {
        'X-Auth0-Token': sessionStorage.getItem('token'),
        'Content-Type': 'multipart/form-data'
      }
    }).then(res => {
      resolve(res)
    })
      .catch(res => {
        reject(res)
      })
  })
}
const upload = (callback, tlist = 0, num = 0, objImg = []) => {
  let count = num
  const list = tlist
  if (list.length > 0) {
    if (list[count]) {
      imageUpTo(list[count]).then(({ data }) => {
        if (data.code === 0) {
          objImg.push(data.data)
          count++
          // this.count = count
          upload(callback, list, count, objImg)
        }
      })
    } else {
      // this.count = 0
      callback(objImg)
    }
  }
}
export default upload
